home *** CD-ROM | disk | FTP | other *** search
- /*
- File: File.c
-
- Contains: This is the FCB dcmd.
-
- Written by: Scott Douglas, Dave Lyons.
-
- Copyright: © 1988,1993-1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 5/13/94 DAL Deal with carriage returns inside filenames (changed put.c).
- <3> 24-Jan-94 JM3 With the Universal Interfaces, EqualString is now in
- TextUtils.h. Blah.
- <2> 9/13/93 DAL made some columns wider and fixed the filename-prefix feature to
- work again
-
- Modification history:
- 29Nov88 sad revised for new dcmd names.
- 5Oct88 sad broke out formatting routines to put.c
- 30Sep88 sad written
-
- The following MPW commands will build the dcmd and copy it to the
- "Debugger Prefs" file in the System folder. The dcmd's name in
- MacsBug will be the name of the file built by the Linker.
- You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
- C Samples folder into this folder.
-
- C Put.c
- C File.c
- Link dcmdGlue.a.o File.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o File
- BuildDcmd File 1003
- Echo 'include "File";' | Rez -a -o "{systemFolder}Debugger Prefs"
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <TextUtils.h>
-
- #include "dcmd.h"
- #include "put.h"
-
- #define FSFCBLen 0x3f6
- #define FCBsPtr 0x34e
-
- typedef struct FCB
- {
- unsigned long fcbFlNum;
- unsigned char fcbMdRByt;
- unsigned char fcbTypByt;
- unsigned short fcbSBlk;
- unsigned long fcbEOF;
- unsigned long fcbPLen;
- unsigned long fcbCrPs;
- VCB* fcbVPtr;
- void* fcbBfAdr;
- unsigned short fcbFlPos;
- unsigned long fcbClmpSize;
- void* fcbBTCBPtr;
- unsigned long fcbExtRec[3];
- OSType fcbFType;
- unsigned long fcbCatPos;
- unsigned long fcbDirID;
- char fcbCName[32];
- } FCB;
-
-
- static void DrawHdr()
- {
- // 1 2 3 4 5 6 7
- // 1234567890123456789012345678901234567890123456789012345678901234567890
- dcmdDrawLine("\pfRef File Vol Type Fl Fork LEof Mark FlNum Parent FCB at");
- }
-
-
- static void DrawFCB(int fref, FCB* fcbp)
- {
- PutUHexWord(fref);
- PutSpace();
- PutPStrTruncTo(fcbp->fcbCName,17+10);
- PutSpace();
- PutPStrTruncTo(fcbp->fcbVPtr->vcbVN,26+10+3);
- PutSpace();
- PutOSType(fcbp->fcbFType);
- PutSpace();
- PutChar((fcbp->fcbMdRByt & 0x80) ? 'D' : 'd');
- PutChar((fcbp->fcbMdRByt & 0x01) ? 'W' : 'w');
- PutSpace();
- if (fcbp->fcbMdRByt & 0x02)
- PutPStr("\prsrc ");
- else
- PutPStr("\pdata ");
- PutUDecTo(fcbp->fcbEOF,47+11+3);
- PutSpace();
- PutUDecTo(fcbp->fcbCrPs,55+12+3);
- PutSpace();
- PutUHexZTo(fcbp->fcbFlNum,6,62+12+3);
- PutSpace();
- PutUHexZTo(fcbp->fcbDirID,6,69+12+3);
- PutSpace();
- PutUHexZTo((unsigned long)fcbp,6,76+12+3);
- PutLine();
- }
-
-
- static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
- // returns true if astr is equal to a prefix of bstr
- // astr must not be longer than 31 characters
- {
- char newstr[31];
- int alen = *astr;
- int blen = *bstr;
- if (alen <= blen)
- {
- BlockMove(bstr+1,newstr+1,alen);
- newstr[0] = alen;
- return EqualString(astr,newstr,false,true);
- }
- else
- return false;
- }
-
-
-
- pascal void CommandEntry(dcmdBlock* paramPtr)
- {
- switch (paramPtr->request)
- {
- case dcmdInit:
- break;
-
- case dcmdHelp:
- dcmdDrawLine("\pfile [fRefNum|\"file name\"]");
- dcmdDrawLine("\p Displays file information on all open files, or for the given fRefNum or filename.");
- dcmdDrawLine("\p Flags are D/d=Dirty, W/w=writeable.");
- break;
-
- case dcmdDoIt:
- {
- Boolean doOneFCB = false;
- long fref;
- short c;
- Boolean haveFileName = false;
- Str255 filename;
- int fcblen; // the length of one fcb
- char* fcbsbase;
- int fcbslen; // the length of the fcbs block
-
- dcmdSwapWorlds();
-
- dcmdDrawLine("\pDisplaying File Control Blocks");
-
- // get low-memory values after dcmdSwapWorlds()
- fcblen = *(unsigned short*)FSFCBLen;
- fcbsbase = *(char**)FCBsPtr;
- fcbslen = *(unsigned short*)fcbsbase;
-
- if (fcblen != sizeof(FCB))
- {
- PutPStr("\FSFCBLen = ");
- PutUDec(fcblen);
- PutPStr("\p expected ");
- PutUDec(fcblen);
- PutLine(sizeof(FCB));
- }
- if ((fcbslen - 2) % fcblen != 0)
- {
- PutPStr("\pBad fcbslen ");
- PutUHexWord(fcbslen);
- PutLine();
- }
-
- c = dcmdPeekAtNextChar();
- if (c == '"' || c == '\'')
- {
- haveFileName = true;
- (void) dcmdGetNextParameter(filename);
- }
- else
- (void) dcmdGetNextExpression(&fref, &doOneFCB);
-
- if (doOneFCB)
- {
- fref = (unsigned short)fref;
- if ((fref > fcbslen) || ((fref - 2) % fcblen != 0))
- {
- PutPStr("\pBad file refnum ");
- PutUHexWord(fref);
- PutLine();
- }
- else
- {
- FCB* fcbp = (FCB*)(fref + fcbsbase);
- if (fcbp->fcbFlNum)
- {
- DrawHdr();
- DrawFCB(fref,fcbp);
- }
- else
- {
- PutPStr("\pFCB ");
- PutUHexWord(fref);
- PutPStr("\p is not in use");
- PutLine();
- }
- }
- }
- else
- {
- int numfcbs = (fcbslen - 2) / fcblen;
- int fcbsused = 0;
- Boolean foundOne = false;
- for (fref = 2; fref < fcbslen; fref += fcblen)
- {
- FCB* fcbp = (FCB*)(fcbsbase + fref);
- if (fcbp->fcbFlNum &&
- (!haveFileName || PrefixPStr(filename,fcbp->fcbCName)))
- {
- fcbsused++;
- if(!foundOne)
- {
- DrawHdr();
- foundOne = true;
- }
- DrawFCB(fref,fcbp);
- }
- if (paramPtr->aborted)
- break;
- }
- if (!paramPtr->aborted)
- if (haveFileName)
- {
- if (!foundOne)
- {
- PutPStr("\pNo open files match \"");
- PutPStr(filename);
- PutChar('"');
- PutLine();
- }
- }
- else
- {
- PutUDec(numfcbs);
- PutPStr("\p FCBs, ");
- PutUDec(fcbsused);
- PutPStr("\p in use, ");
- PutUDec(numfcbs - fcbsused);
- PutPStr("\p free");
- PutLine();
- }
- }
-
- dcmdSwapWorlds();
- break;
- }
-
- default:
- PutPStr("\punknown request ");
- PutUDec(paramPtr->request);
- PutLine();
- break;
- }
- }
-